﻿using PRO.DbProvider;
using PRO.Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using PRO.Common;
using PRO.ORM;

namespace PRO.Data.SqlServer
{
    public partial class DataProvider : IDataProvider
    {
        public int AddToFavorite(FavoriteInfo info)
        {
            int r = 0;
            if (info.PID > 0 && info.UserID > 0)
            {
                string sql = "SELECT count(id) FROM Pro_Favorite where pid=" + info.PID + " and userid=" + info.UserID;
                if (DbHelper.ExecuteScalar(CommandType.Text, sql).ToString().ToInt(0) == 0)
                {
                    if (info.Insert() > 0)
                        r = 1;
                }
                else
                    r = -2;
            }
            return r;
        }
        public bool DelToFavorite(int id, int userid)
        {
            string sql = "delete Pro_Favorite where id=" + id + " and userid=" + userid;
            return Convert.ToBoolean(DbHelper.ExecuteNonQuery(CommandType.Text, sql));
        }
    }
}
